/*
package com.klouda.platakybeta;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class LekyViewActivity extends Activity {

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_leky_view);
  }

  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    //!td getMenuInflater().inflate(R.menu.activity_leky_view, menu);
    return true;
  }

}

*/

//
//!td je to prelozitelne, ale zatim nefunkcni
package com.klouda.platakybeta;
import com.klouda.platakybeta.db.PlatakyDbHandler;

import android.os.AsyncTask;
import android.os.Bundle;
import android.app.ListActivity;
import android.content.Intent;
import android.database.Cursor;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.CursorAdapter;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.AdapterView.OnItemClickListener;

public class LekyViewActivity extends ListActivity {
  
   public static final String ROW_ID = "row_id";
   private ListView conListView;
   private CursorAdapter conAdapter;
   
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        conListView=getListView();
        conListView.setOnItemClickListener(viewConListener);
        // map each name to a TextView
        String[] from = new String[] { "name" };
        int[] to = new int[] { R.id.countryTextView };
        conAdapter = new SimpleCursorAdapter(LekyViewActivity.this, R.layout.activity_leky_view, null, from, to, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
        setListAdapter( conAdapter); // set adapter
    }
    @Override
    protected void onResume()
    {
       super.onResume();
       //!td misto void tam bylo Object[]
       new GetContacts().execute((Void) null);
     }
    @Override
    protected void onStop()
    {
       Cursor cursor = conAdapter.getCursor();
       if (cursor != null)
          //!td je to deprecated cursor.deactivate();
         cursor.close();
       conAdapter.changeCursor(null);
       super.onStop();
    }
    private class GetContacts extends AsyncTask<Void, Void, Cursor>
    {
       PlatakyDbHandler dbConnector = new PlatakyDbHandler(LekyViewActivity.this);
       @Override
       protected Cursor doInBackground(Void... params)
       {
          dbConnector.open();
          return dbConnector.getAllLeky();
       }
       
       @Override
       protected void onPostExecute(Cursor result)
       {
          conAdapter.changeCursor(result); // set the adapter's Cursor
          dbConnector.close();
       }
    }
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu)
    {
       super.onCreateOptionsMenu(menu);
       MenuInflater inflater = getMenuInflater();
       //inflater.inflate(R.menu.country_menu, menu);
       return true;
    }
    @Override
    public boolean onOptionsItemSelected(MenuItem item)
    {
       Intent addContact = new Intent(LekyViewActivity.this, LekEditActivity.class);
       startActivity(addContact);
       return super.onOptionsItemSelected(item);
    }
    OnItemClickListener viewConListener = new OnItemClickListener()
    {
       public void onItemClick(AdapterView arg0, View arg1, int arg2,long arg3)
       {
          Intent viewCon = new Intent(LekyViewActivity.this, LekEditActivity.class);
          viewCon.putExtra(ROW_ID, arg3);
          startActivity(viewCon);
       }
    };
}